<?php

/**
 * Description of components
\* www.teuker.nl - mail@teuker.nl
 * 
 * @author francisc
 */

class globalsComponents extends sfComponents {

    public function executeConsole(sfWebRequest $request) {
        if ('1' != $this->getUser()->getAttribute('console'))
            return sfView::NONE;

        $this->console_messages = SqlEngine::getConsoleReservations(array(
                                        'restaurant_id' => $this->getUser()->getAttribute('current_restaurant_id'),
                                        'user_id' => $this->getUser()->getAttribute('user_id')));

        /* store the created_at value of the last reservation as a reference for new reservations */
        if (!empty($this->console_messages))
            $this->getUser()->setAttribute('last_console_message_created_at',
                    $this->console_messages[count($this->console_messages) - 1]['last_created_at']);
    }

    public function executeSpecialDates(sfWebRequest $request) {
        $restaurant_id = $this->getUser()->getAttribute('current_restaurant_id');
        
        $settings = SqlEngine::getSettings(array('restaurant_id' => array('value' => $restaurant_id, 'type' => PDO::PARAM_INT)));
        $this->special_dates = SqlEngine::getSpecialDates(array('restaurant_id' => array('value' => $restaurant_id, 'type' => PDO::PARAM_INT),
                                                                'count' => $settings['special_dates_no']));
    }
    
    public function executeGuestSpecialDates(sfWebRequest $request) {
        $restaurant_id = $this->getUser()->getAttribute('current_restaurant_id');
        
        $settings = SqlEngine::getSettings(array('restaurant_id' => array('value' => $restaurant_id, 'type' => PDO::PARAM_INT)));
        $this->guest_special_dates = SqlEngine::getSpecialDates(array('restaurant_id' => array('value' => $restaurant_id, 'type' => PDO::PARAM_INT),
                                                                'count' => $settings['special_dates_no']));
    }
    
    //TODO: added HV 9-9-2011 to fix special date buttons on the back office form.
	public function executeBackofficeSpecialDates(sfWebRequest $request) {
        $restaurant_id = $this->getUser()->getAttribute('current_restaurant_id');
        
        $settings = SqlEngine::getSettings(array('restaurant_id' => array('value' => $restaurant_id, 'type' => PDO::PARAM_INT)));
        $this->guest_special_dates = SqlEngine::getSpecialDates(array('restaurant_id' => array('value' => $restaurant_id, 'type' => PDO::PARAM_INT),
                                                                'count' => $settings['special_dates_no']));
    }
    
    

    public function executeMenuList(sfWebRequest $request) {
        $restaurant_id = $this->getUser()->getAttribute('current_restaurant_id');

        $this->menu_list = SqlEngine::getMenus(array('restaurant_id' => $restaurant_id));
        $this->settings = SqlEngine::getSettings(array('restaurant_id' => $restaurant_id));
    }

    public function executeRestaurantDropdown(sfWebRequest $request) {
        $this->restaurants = Valuelist::getRestaurantsChoices(array('user_id' => $this->getUser()->getAttribute('user_id')));
    }
    
    public function executeReservationLog(sfWebRequest $request) {
        $this->logs = array();
        
        //FIXME This fails
        /*
         if (null != $this->reservationId)
            $this->logs = SqlEngine::getReservationLogs($this->reservationId);
        */
    }
    
}
